layui.use(['layer', 'form', 'admin', 'ax', 'laytpl'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laytpl = layui.laytpl;

    var id = system.getUrlParam('id');

    //获取菜单信息
    var ajaxData = new $ax(system.contextPath + "/api/role.get");
    ajaxData.setType("get");
    ajaxData.set({id: id});
    var resultData = ajaxData.start();
    form.val('formContainer', resultData.data);

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(system.contextPath + "/api/role.update", function (res) {
            if (res.status) {
                system.success("修改成功！");
                //传给上个页面，刷新table用
                admin.putTempData('formOk', true);
                //关掉对话框
                admin.closeThisDialog();
            } else {
                system.error("修改失败！" + res.msg)
            }
        }, function (res) {
            system.error("修改失败！" + res.msg)
        });
        data.field.id = id;
        ajax.set(data.field);
        ajax.start();

        return false;
    });
});